home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVI_DVI1 / dvilj / c / dvichars < prev    next >
Text File  |  1996-01-07  |  30KB  |  1,084 lines

  1. #include "dvilj.h"
  2.  
  3.  
  4.  
  5. /*-->EmitChar*/
  6. /**********************************************************************/
  7. /****************************  EmitChar  ******************************/
  8. /**********************************************************************/
  9. void                     /* output a character bitmap */
  10. EmitChar(long4 c, struct char_entry *ce)
  11. {
  12.     register int    i;
  13.     register unsigned char  *sl;
  14.     unsigned short  nbpl, nwpl;
  15.     long4    total;
  16. #ifdef LJ
  17.     unsigned char cnv_buffer[10];
  18. #endif
  19.  
  20.  
  21. #ifdef LJ
  22. /*
  23. printf("Emit character %c(%d) id=%d, yoff=%d[%d], w=%d[%d], h=%d[%d]\n",
  24.         (char)c,(int)c,
  25.     fontptr->plusid,
  26.     ce->yOffset, fontptr->max_yoff,
  27.     ce->width,   fontptr->max_width,
  28.     ce->height,  fontptr->max_height
  29. );
  30. */
  31. #endif
  32.  
  33.  
  34.  
  35.     if ( fontptr->ncdl == 0 ) {
  36. #ifdef IBM3812
  37.         used_fontstorage += 1028;
  38. #endif
  39. #ifdef LJ
  40.         if (fontptr->max_width == 0) { /* we have no realistic values */
  41.                 fontptr->max_yoff = CHAR_HEIGTH_LARGE;
  42.                 fontptr->max_width = CHAR_WIDTH_LARGE;
  43.                 fontptr->max_height = CHAR_HEIGTH_LARGE*2;
  44.         }
  45.  
  46.         /* open font dict before first char, set active font */
  47.         INT_ASCII(cnv_buffer,fontptr->plusid);
  48. #ifdef LJ4
  49.         EMIT(EMTO, "\033*c%sD\033)s68W", cnv_buffer); EMFLUSH;
  50.         EMITB(6, "\0\104\024\2\0\0");
  51. #else
  52.         EMIT(EMTO, "\033*c%sD\033)s26W", cnv_buffer); EMFLUSH;
  53. #ifdef SEVENBIT
  54.         EMITB(6, "\0\032\0\1\0\0");
  55. #else
  56.         EMITB(6, "\0\032\0\2\0\0");
  57. #endif
  58. #endif /* LJ 4 */
  59.         EMITWORD( fontptr->max_yoff);
  60.         EMITWORD( fontptr->max_width);
  61.         EMITWORD( fontptr->max_height);
  62.         EMITB(8, "\0\1\1\25\0\4\0\4");
  63.         EMITB(6, "\0\0\0\0\0\0");
  64. #ifdef LJ4
  65.     EMITB(22,"\0\0\0\0\0\0\0\0\0\0\0\0\0\377\0\0\0\0\0\0\0\0");
  66.     EMITB(16,"                ");
  67.     EMITB(4 ,"\2\130\2\130");
  68. #endif
  69.         EMIT(EMTO, "\033*c4F"); EMFLUSH;
  70. #endif
  71.     }
  72.     if ( fontptr != prevfont ) {   /* because this isn't done on pass 0 */
  73. #ifdef LJ
  74.         INT_ASCII(cnv_buffer,fontptr->plusid);
  75.         EMIT(EMTO, "\033(%sX", cnv_buffer); EMFLUSH;
  76. #endif
  77.         prevfont = fontptr;
  78.     }
  79.  
  80. #ifdef USEPXL
  81.     if (fontptr->id == pk89)   {
  82.         nwpl = 0; /* initialize variable */
  83.         nbpl = ((int)(ce->width) +  7) >> 3;
  84.         total = (long4)ce->height * nbpl;
  85.     } else if (fontptr->id == id1002)   {
  86.         nwpl = 0; /* initialize variable */
  87.         nbpl = ((int)(ce->width) +  7) >> 3;
  88.         total = (long4)ce->height * nbpl;
  89.     } else if (fontptr->id == id1001) {
  90.         nwpl = ((int)(ce->width) + 31) >> 5;
  91.         nbpl = ((int)(ce->width) + 7) >> 3;
  92.         total = (long4)ce->height * nbpl;
  93.     } else {
  94.       /* should never be necessary */
  95.       nwpl = 0;
  96.       nbpl = 0;
  97.       total = 0;
  98.     }
  99. #else
  100.     nbpl = (num_cols + 7) >> 3;
  101.     total = num_rows * nbpl;
  102. #endif
  103. /***************************************************************
  104.     if ( ((char) c == 'i') && (fontptr->plusid == 0)) {
  105.         long4 j;
  106.         fprintf(ERR_STREAM, "cols=%ld, ncols=%ld\n",(long)nwpl,(long)nbpl);
  107.  
  108.         fprintf(ERR_STREAM, "%ld Bytes:->",(long)total);
  109.         for (j=0; j<total;j++) {
  110.             char *ch; char ic;
  111.             ch = (char *)(ce->where.address.pixptr);
  112.             ic = *(ch+j);
  113.             fprintf(ERR_STREAM,"%X.",ic);
  114.                 }
  115.         fprintf(ERR_STREAM,"<- Now Emitting\n");
  116.         }
  117. ***************************************************************/
  118. #ifdef USEPXL
  119. #ifdef IBM3812
  120.     if ((short)(ce->height) - ce->yOffset > 55) {
  121.         ce->yyOffset = (short) ce->height - ce->yOffset;
  122.         ce->yOffset  = (short) ce->height;
  123.     } else {
  124.         ce->yyOffset = (short) 0;
  125.     }
  126. #endif
  127. #ifdef LJ
  128.         ce->yyOffset = (short) 0;
  129. #endif
  130. #endif
  131.  
  132.     /* ce->cw = (long4)(((double)ce->tfmw / (double)hconv) +0.5); */
  133.     /* set active font to nn, load font pattern  xx ... */
  134. #ifdef IBM3812
  135.     PMPcont(total + 9);
  136. #ifdef USEPXL
  137.     sprintf(PMPformat, "\323%c\360%c%c%c",
  138.         (unsigned char)fontptr->plusid,
  139.         (unsigned char)VisChar((char)c),
  140.         (unsigned char)ce->height,
  141.         (unsigned char)ce->width);
  142.     PMPout(6, PMPformat);
  143.     PMPoutC((char)(-(ce->xOffset)));
  144.     PMPoutC((char)(ce->cw - (-ce->xOffset + ce->width)));
  145.     PMPoutC((char)(ce->yOffset));
  146. #else
  147.     sprintf(PMPformat, "\323%c\360%c%c%c",
  148.         (unsigned char)fontptr->plusid,
  149.         (unsigned char)VisChar((char)c),
  150.         (unsigned char)num_rows,
  151.         (unsigned char)num_cols);
  152.     PMPout(6, PMPformat);
  153.     PMPoutC((char)(-x_offset));
  154.     PMPoutC((char)(ce->cw - (-x_offset + num_cols)));
  155.     PMPoutC((char)num_rows-y_offset);
  156. #endif
  157. #endif
  158. #ifdef LJ
  159.     INT_ASCII(cnv_buffer,fontptr->plusid);
  160.     EMIT(EMTO, "\033*c%sd%dE\033(s%ldW", cnv_buffer,
  161.         (unsigned int)VisChar((char)c), (long)(total + 16)); EMFLUSH;
  162.     EMITB(4, "\4\0\016\1");
  163. /*    EMITC((char)(Landscape==_TRUE)); */
  164.     EMITC((char)0);
  165.     EMITC((char)0);
  166. #ifdef USEPXL
  167.     EMITWORD(-ce->xOffset);
  168.     EMITWORD(ce->yOffset);
  169.     EMITWORD(ce->width);
  170.     EMITWORD(ce->height);
  171. #else
  172.     EMITWORD(-x_offset);
  173.     EMITWORD(num_rows-y_offset);
  174.     EMITWORD(num_cols);
  175.     EMITWORD(num_rows);
  176. #endif
  177.     EMITWORD((int)ce->cw * 4);
  178. #endif
  179. #ifdef USEPXL
  180.  
  181.     if (fontptr->id == pk89)
  182.         PkRaster(ce, _FALSE);
  183.     else if (fontptr->id == id1002)
  184.         for (i = 0; i < (int) ce->height; i++) {
  185.             sl = ((unsigned char *)(ce->where.address.pixptr) + i * nbpl);
  186.             EMITL(nbpl, sl);
  187.         }
  188.     else if (fontptr->id == id1001)
  189.         for (i = 0; i < (int) ce->height; i++) {
  190.             sl = (unsigned char *)(ce->where.address.pixptr + i * nwpl);
  191.             EMITL(nbpl, sl);
  192.         }
  193. #else
  194.     for (i = num_rows; i > 0; i--)
  195.       {
  196.         EMITL (nbpl, bits + (i-1) * nbpl);
  197.       }
  198. #endif
  199. #ifdef IBM3812
  200. #ifdef USEPXL
  201.     used_fontstorage += (long4)ce->height * ((ce->width + 15) >> 4)
  202.         *2 + 14;
  203. #else
  204.     used_fontstorage += (long4)num_rows * ((num_cols + 15) >> 4)
  205.         *2 + 14;
  206. #endif
  207. #endif
  208. #ifdef LJ
  209. #ifdef USEPXL
  210.     used_fontstorage += 64 * (((int)((ce->height * ce->width) - 1) / 64) + 1);
  211. #else
  212.     used_fontstorage += 64 * ((((num_rows * num_cols) - 1) / 64) + 1);
  213. #endif
  214. #endif
  215.     fontptr->ncdl += 1;
  216.     G_ncdl += 1;
  217. }
  218.  
  219.  
  220.  
  221. /*********************************************************************/
  222. /**************************** PK Raster ******************************/
  223. /*********************************************************************/
  224.  
  225. #ifdef USEPXL
  226. bool getbit ();
  227. unsigned char   getnyb (void);
  228. long4    pk_packed_num (void);
  229.  
  230.  
  231. #define  PKBYTE   *pkloc; pkloc ++
  232. #define  OUTCHAR(c) raster_line_buf[bp]= (unsigned char)c; bp++
  233.  
  234. unsigned char   bitweight, inputbyte ;
  235. unsigned char   dyn_f ;
  236. unsigned char   *pkloc;
  237. int     repeatcount;
  238.  
  239. void              /* <Read and translate raster description@>*/
  240. PkRaster(struct char_entry *ce, bool raster)
  241. {
  242.     int     rp;
  243.     int     current_line;
  244.     int     wordwidth ;
  245.     bool turnon;
  246.     unsigned short  nbpl;
  247.     long4    rowsleft, word, wordweight, hbit, count, i, j, tl;
  248.     long4    row[101] ;
  249.     unsigned char   raster_line_buf[BYTES_PER_PIXEL_LINE];
  250.     unsigned short  bp;
  251.  
  252.  
  253.     if (ce->charsize == HUGE_SIZE)
  254.         Fatal( "cannot process currently PK font patterns of that size!\n");
  255.  
  256.  
  257.     current_line = 0;
  258.     pkloc = (unsigned char *)ce->where.address.pixptr;
  259.     dyn_f = (unsigned char)(ce->flag_byte >> 4);
  260.     turnon = (bool)((ce->flag_byte & 8) == 8);
  261.     wordwidth = (int)(ce->width + 31) >> 5 ;
  262.     nbpl = ((int)(ce->width) +  7) >> 3;
  263.  
  264.     bitweight = 0 ;
  265.     if (dyn_f == 14) {
  266.         /*printf("<Get raster by bits@>\n");*/
  267.         for (i = 1; i <= (long4)ce->height; i++) {
  268.         word = 0 ;
  269.         wordweight = 31 ;
  270.         bp = 0;            /* Sowa */
  271.  
  272. #ifdef DRAWGLYPH
  273.            printf("     |");
  274. #endif
  275.         for (j = 1; j <= (long4) ce->width; j++) {
  276.             bool getbit;
  277.             /* bp = 0;               SOWA */
  278. /*******************************************begin Getbit *********/
  279.             bitweight /= 2 ;
  280.             if ( bitweight == 0 ) {
  281.                 inputbyte = PKBYTE ;
  282.                 bitweight = 128 ;
  283.             }
  284.             getbit = (bool)
  285.              ( inputbyte >= bitweight ) ;
  286.             if ( getbit )
  287.                 inputbyte -= bitweight ;
  288. /*********************************************end Getbit *********/
  289.  
  290.             if (getbit)
  291.                 word += power[wordweight] ;
  292.  
  293.             wordweight --;
  294.             if (wordweight == -1) {
  295.  
  296. #ifdef DRAWGLYPH
  297.    { int k;
  298.      for (k=31; k>=0; k--) {
  299.          if ((power[k] & word)!=0) printf("M");
  300.          else printf(".");
  301.      }
  302.    }
  303. #endif
  304.  
  305.             OUTCHAR((word >> 24 & 0xFF));
  306.             OUTCHAR((word >> 16 & 0xFF));
  307.             OUTCHAR((word >> 8 & 0xFF));
  308.             OUTCHAR((word    & 0xFF));
  309.  
  310.             word = 0 ;
  311.             wordweight = 31 ;
  312.             }
  313.         }
  314.         if (wordweight < 31) {
  315. #ifdef COMMENT
  316. #ifdef DRAWGLYPH
  317.    { int k;
  318.      for (k=15; k>=0; k--) {
  319.         if ((power[k] & word)!=0) printf("Z");
  320.         else printf(":");
  321.      }
  322.     }
  323.     printf("|\n ----|");
  324. #endif
  325. #endif
  326.  
  327.             for (j = 3; j >= (wordwidth * 4 - (long4)nbpl);
  328.             j--) {
  329.  
  330.                 OUTCHAR(((word >> (j << 3)) & 0xff));
  331.  
  332. #ifdef DRAWGLYPH
  333.    { int k;
  334.      for (k=7; k>=0; k--) {
  335.         if ((power[k] & ((word >> (j << 3)) & 0xff))!=0) printf("M");
  336.         else printf(".");
  337.      }
  338.    }
  339. #endif
  340.  
  341.             }
  342.         }
  343.  
  344.         if (raster) {
  345.             RasterLine(ce, (unsigned int)nbpl,
  346.                 current_line, raster_line_buf);
  347.             current_line++;
  348.         } else
  349.             EMITL(bp, raster_line_buf);
  350.  
  351. #ifdef DRAWGLYPH
  352.    printf("|\n");
  353. #endif
  354.         }
  355.     } else {
  356.         /* fprintf(ERR_STREAM, "@<Create normally packed raster@>\n"); */
  357.         rowsleft = (long4) ce->height ;
  358.         hbit = (long4) ce->width ;
  359.         repeatcount = 0 ;
  360.         wordweight = 32 ;
  361.         word = 0 ;
  362.         rp = 1 ;
  363.         while ( rowsleft > 0 ) {
  364.         count = pk_packed_num() ;
  365.         bp = 0;
  366.  
  367.         while (count > 0) {
  368.             if ((count < wordweight) && (count < hbit)) {
  369.             if (turnon)
  370.                 word +=
  371.                     gpower[wordweight] -
  372.                     gpower[wordweight - count] ;
  373.  
  374.             hbit -= count ;
  375.             wordweight -= count ;
  376.             count = 0 ;
  377.             } else if ((count >= hbit) && (hbit <=
  378.             wordweight)) {
  379.  
  380.             if (turnon)
  381.                 word +=
  382.                     gpower[wordweight] -
  383.                     gpower[wordweight - hbit] ;
  384.  
  385.             row[rp] = word ;
  386.  
  387.             /*fprintf(ERR_STREAM, " @<Send row@> \n");*/
  388.             for (i = 0; i <= (long4) repeatcount; i++) { int ii;
  389.  
  390. #ifdef DRAWGLYPH
  391.   printf("***  |");
  392. #endif
  393.                 for (ii = 1; ii < wordwidth; ii++) {
  394.                 tl = row[ii];
  395.  
  396.                 OUTCHAR((tl >> 24 & 0xFF));
  397.                 OUTCHAR((tl >> 16 & 0xFF));
  398.                 OUTCHAR((tl >> 8  & 0xFF));
  399.                 OUTCHAR((tl       & 0xFF));
  400.  
  401. #ifdef DRAWGLYPH
  402.    { int k;
  403.      for (k=31; k>=0; k--)  {
  404.          if ((power[k] & row[ii])!=0) printf("M");
  405.          else printf(".");
  406.      }
  407.    }
  408. #endif
  409.                 }
  410.                 tl = row[wordwidth];
  411.                 for (j = 3; j >= (wordwidth *4 - (long4)nbpl);
  412.                  j--) {
  413.  
  414.                  OUTCHAR(((tl >> (j << 3)) & 0xff));
  415.  
  416. #ifdef DRAWGLYPH
  417.    { int k;
  418.      for (k=7; k>=0; k--) {
  419.          if ((power[k] & ((tl >> (j << 3)) & 0xff))!=0) printf("M");
  420.          else printf(".");
  421.      }
  422.    }
  423. #endif
  424.                 }
  425.  
  426.                 if (raster) {
  427.                     RasterLine(ce,
  428.                     (unsigned int)nbpl,
  429.                      current_line,
  430.                      raster_line_buf);
  431.                     current_line++;
  432.                 } else
  433.                     EMITL(bp, raster_line_buf);
  434.  
  435.                 bp = 0;
  436.  
  437. #ifdef DRAWGLYPH
  438.    printf("|  ");
  439.    for (j=1;j<=(long4)wordwidth;j++) printf("%02lX/",row[j]);
  440.    printf(" raster=%d\n",raster);
  441. #endif
  442.             }
  443.  
  444.             rowsleft -=  (long4)repeatcount + 1 ;
  445.             repeatcount = 0 ;
  446.             rp = 1 ;
  447.             word = 0 ;
  448.             wordweight = 32 ;
  449.             count -= hbit ;
  450.             hbit = (long4)ce->width ;
  451.             } else {
  452.             if (turnon) word += gpower[wordweight] ;
  453.             row[rp] = word ;
  454.             rp = rp + 1 ;
  455.             word = 0 ;
  456.             count -= wordweight ;
  457.             hbit -= wordweight ;
  458.             wordweight = 32 ;
  459.             }
  460.         }   /* .....while count > 0 */
  461.         if (turnon)
  462.             turnon = _FALSE;
  463.         else
  464.             turnon = _TRUE;
  465.         } /* ...... rowsleft > 0 */
  466.         if ((rowsleft != 0) || (hbit != (long4)ce->width))
  467.             Fatal("Bad pk file----more bits than required!\n");
  468.     } /* .... create normally packed raster */
  469. }
  470.  
  471.  
  472. unsigned char   getnyb (void)
  473. {
  474.     register unsigned char  temp ;
  475.     if ( bitweight == 0 ) {
  476.         inputbyte = PKBYTE ;
  477.         bitweight = 16 ;
  478.     }
  479.     temp = inputbyte / bitweight ;
  480.     inputbyte -= temp * bitweight ;
  481.     bitweight /= 16 ;
  482.     return ( temp ) ;
  483. }
  484.  
  485.  
  486. long4
  487. pk_packed_num (void)
  488. { /*@<Packed number procedure@>= */
  489.     register int    i;
  490.     long4    j;
  491.  
  492.     i = (int)getnyb();
  493.     if (i == 0) {
  494.         do {
  495.             j = (long4)getnyb();
  496.             i++;
  497.         } while (j == 0) ;
  498.         while (i > 0) {
  499.             j = j * 16 + (long4)getnyb() ;
  500.             i--;
  501.         };
  502.         return (j - 15 + (13 - dyn_f) * 16 + dyn_f) ;
  503.     } else if (i <= (int)dyn_f) {
  504.         return ((long4)i);
  505.     } else if (i < 14) {
  506.         return ((i-(long4)dyn_f - 1) * 16 + (long4)getnyb() + dyn_f + 1);
  507.     } else {
  508.         if (i == 14) {
  509.             repeatcount = (int) pk_packed_num() ;
  510.         } else {
  511.             repeatcount = 1 ;
  512.         }
  513.         /*     fprintf(ERR_STREAM,"repeatcount = [%d]\n",repeatcount);    */
  514.         return (pk_packed_num()) ;    /* tail end recursion !! */
  515.     }
  516. }
  517. #endif
  518.  
  519. #ifndef USEPXL
  520. void bad_gf(int n)
  521. {
  522.     Fatal("Bad gf file, case %d\n",n);      /* See gf.c */
  523. }
  524. #endif
  525.  
  526.  
  527.  
  528. /*-->RasterLine*/
  529. /**********************************************************************/
  530. /****************************  RasterLine  ****************************/
  531. /**********************************************************************/
  532. void
  533. RasterLine(struct char_entry *ce, unsigned short nbpl, unsigned short current_line, char *buffer)
  534. {
  535. #ifdef IBM3812
  536.     long4    total;
  537.     static unsigned short   maxlines;
  538.  
  539.     if (current_line == 0) {
  540. #ifdef USEPXL
  541.         maxlines = ce->height;
  542.  
  543.         MoveVert(-ce->yOffset);      /* move cursor up */
  544.         MoveHor(-ce->xOffset);       /* move cursor right */
  545. #else
  546.         maxlines = num_rows;
  547.  
  548.         MoveVert(-(num_rows-y_offset));      /* move cursor up */
  549.         MoveHor(-x_offset);       /* move cursor right */
  550. #endif
  551.         last_ry = UNKNOWN;       /* next time full positioning */
  552.     }
  553.  
  554.     if (current_line % maxlines == 0) {
  555.         if (current_line > 0) {    /* maxlines lines have been printed*/
  556.             MoveVert(maxlines);   /*   move cursor down     */
  557.             last_ry = UNKNOWN;    /* next time full positioning */
  558.         }
  559. #ifdef USEPXL
  560.         total = (long4)(ce->height - current_line) * (long4)nbpl;
  561. #else
  562.         total = (long4)(num_rows - current_line) * (long4)nbpl;
  563. #endif
  564.         if ((total + 9) > 65535) {
  565.             maxlines = (unsigned short)((65535 - 9) / nbpl);
  566.             total = (long4)maxlines * (long4)nbpl;
  567.         }
  568.  
  569.         PMPcont(total + 9);
  570.         PMPout(2, "\365\0");
  571.         EMITWORD(maxlines);
  572. #ifdef USEPXL
  573.         EMITWORD(ce->width);
  574. #else
  575.         EMITWORD(num_cols);
  576. #endif
  577.         PMPoutC((unsigned char) (total >> 16) & 0xFF);
  578.         PMPoutC((unsigned char) (total >> 8 ) & 0xFF);
  579.         PMPoutC((unsigned char)  total     & 0xFF);
  580.     }
  581.     EMITL((int)nbpl, buffer);
  582. #endif
  583. #ifdef LJ
  584.     register int    emitbytes;
  585.  
  586.     for (emitbytes = (int)nbpl;
  587.         (*(buffer + emitbytes - 1) == '\0') && (emitbytes > 0);
  588.         emitbytes--) ;
  589.     EMIT(EMTO, "\033*b%dW", emitbytes); EMFLUSH;
  590.     EMITL(emitbytes, buffer);
  591. #endif
  592. }
  593.  
  594.  
  595. /*-->RasterChar*/
  596. /**********************************************************************/
  597. /****************************  RasterChar  ****************************/
  598. /**********************************************************************/
  599. void                     /* raster a character bitmap */
  600. RasterChar(struct char_entry *ce)
  601. {
  602.     int     i;
  603.     register unsigned char  *sl;
  604.     unsigned short  nbpl, nwpl;
  605.     unsigned char   raster_line_buf[BYTES_PER_PIXEL_LINE];
  606.  
  607. #ifdef DEBUG
  608.     if (Debug)
  609.         fprintf(ERR_STREAM,"Raster character ...size=%d \n", (int)ce->charsize );
  610. #endif
  611.  
  612. #ifdef USEPXL
  613.     if (fontptr->id == pk89)   {
  614.         nwpl = 0; /* initialize variable */
  615.         nbpl = ((int)(ce->width) +  7) >> 3;
  616.     } else if (fontptr->id == id1002)   {
  617.         nwpl = 0; /* initialize variable */
  618.         nbpl = ((int) ce->width +  7) >> 3;
  619.     } else if (fontptr->id == id1001) {
  620.         nwpl = ((int) ce->width + 31) >> 5;
  621.         nbpl = ((int) ce->width + 7) >> 3;
  622.     } else {
  623.       /* should never be necessary */
  624.       nwpl = 0;
  625.       nbpl = 0;
  626.     }
  627. #else
  628.     nbpl = (num_cols + 7) >> 3;
  629. #endif
  630.  
  631. #ifdef LJ
  632.     EMIT(EMTO, "\033*t%dR\033*r1A",RESOLUTION); EMFLUSH;
  633. #endif
  634.                                             { /* read pixel from file */
  635.     if ((ce->charsize == HUGE_SIZE) && (fontptr->id != pk89))
  636.         OpenFontFile();
  637. #ifdef USEPXL
  638.         FSEEK(pxlfp, ce->where.address.fileOffset,SEEK_SET);
  639. #else
  640.         FSEEK(gfin, ce->where.address.fileOffset,SEEK_SET);
  641.         gettochar();
  642.         readbits();
  643. #endif
  644.     }
  645.  
  646. #ifdef USEPXL
  647.     if (fontptr->id == pk89)
  648.         PkRaster(ce, _TRUE);
  649.     else if (fontptr->id == id1002) {
  650.         for (i = 0; i < (int) ce->height; i++) {
  651.             if (ce->charsize == HUGE_SIZE) {
  652.                 read_multi(raster_line_buf, 1, (int) nbpl, pxlfp);
  653.                 sl = raster_line_buf;
  654.             } else
  655.                 sl = ((unsigned char *)(ce->where.address.pixptr)
  656.                     + i * nbpl);
  657.  
  658.             RasterLine(ce, (unsigned int)nbpl, i, sl);
  659.         }
  660.     } else if (fontptr->id == id1001) {
  661.         long4    filediff;
  662.         filediff = (long4)nwpl * 4 - nbpl;
  663.         for (i = 0; i < (int) ce->height; i++) {
  664.             if (ce->charsize == HUGE_SIZE) {
  665.                 read_multi(raster_line_buf, 1, (int) nbpl, pxlfp);
  666.                 /* skip fill bytes */
  667.                 FSEEK(pxlfp, filediff,SEEK_CUR);
  668.                 sl = raster_line_buf;
  669.             } else
  670.                 sl = (unsigned char *)(ce->where.address.pixptr + i * nwpl);
  671.  
  672.             RasterLine(ce, (unsigned int)nbpl, i, sl);
  673.         }
  674.     }
  675. #else
  676.     for (i = num_rows; i > 0; i--)
  677.       RasterLine(ce, (unsigned int)nbpl, i, bits + (i-1) * nbpl);
  678. #endif
  679. #ifdef LJ
  680.     EMIT(EMTO, "\033*rB"); EMFLUSH;
  681. #endif
  682.     last_ry = UNKNOWN;
  683. }
  684.  
  685.  
  686. /*-->LoadAChar*/
  687. /**********************************************************************/
  688. /***************************** LoadAChar ******************************/
  689. /**********************************************************************/
  690. void
  691. LoadAChar(long4 c, register struct char_entry *ptr)
  692. {
  693.     long4    *pr;
  694.     long4    bytes;
  695.  
  696.     if (ptr->where.address.fileOffset == NONEXISTANT
  697. #ifdef LJ_RESIDENT_FONTS
  698.     || fontptr->resident_p
  699. #endif
  700.     ) {
  701.       ptr->where.isloaded = _FALSE;
  702.       return;
  703.     }
  704.  
  705.     OpenFontFile();
  706.  
  707. #ifdef DEBUG
  708.     if (Debug)
  709.       fprintf(ERR_STREAM, "LoadAChar: <%c>(%ld) from file at pos %ld\n",
  710.           (char)c,(long)c,(long)ptr->where.address.fileOffset);
  711. #endif
  712.  
  713. #ifdef USEPXL
  714.  
  715.     FSEEK(pxlfp, ptr->where.address.fileOffset,SEEK_SET);
  716.  
  717.     if (fontptr->id == pk89) {
  718. #ifdef PARANOIA
  719.         unsigned char   temp;
  720.         temp = (unsigned char) NoSignExtend(pxlfp, 1);
  721.  
  722.         if ((int)(ptr->flag_byte) != (int)temp) {
  723.            fprintf(ERR_STREAM,"font=%lx, ptr=%lx\n",fontptr,ptr);
  724.                 Fatal("%d: oh boy! old flag %d, new flag %d, ptr=%lx\n",
  725.                           (int)c,(int)(ptr->flag_byte),(int)temp,ptr);
  726.             }
  727. #endif
  728.  
  729.         if ((ptr->flag_byte & 7) == 7) {
  730.             bytes = ((long4) NoSignExtend(pxlfp, 4)) - 28;
  731.             FSEEK(pxlfp, ptr->where.address.fileOffset + 36,SEEK_SET);
  732. /*
  733. fprintf(ERR_STREAM,"bytes=%ld, seeking at %ld\n",
  734.             (long)bytes, (long)ptr->where.address.fileOffset + 36);
  735. */
  736.         } else if ((ptr->flag_byte & 4) == 4) {
  737.             bytes = ((long4)ptr->flag_byte & 3)
  738.                 * 65536l + NoSignExtend(pxlfp, 2) - 13;
  739.             FSEEK(pxlfp, ptr->where.address.fileOffset + 16,SEEK_SET);
  740.         } else {
  741.             bytes = ((long4)ptr->flag_byte & 3)
  742.                 * 256 + NoSignExtend(pxlfp, 1) - 8;
  743.             FSEEK(pxlfp, ptr->where.address.fileOffset + 10,SEEK_SET);
  744.         }
  745.     } else if (fontptr->id == id1002)
  746.         bytes =  ((( (long4)ptr->width + 7) >> 3) * (long4) ptr->height);
  747.     else if (fontptr->id == id1001)
  748.         bytes =  4 * (((long4)ptr->width + 31) >> 5) * (long4)ptr->height;
  749.     else
  750.         bytes = 0;
  751.  
  752.     if (bytes > 0) {
  753.                                           /* do NOT load Huge characters */
  754.       if ((bytes > HUGE_CHAR_PATTERN) && (fontptr->id != pk89)) {
  755.     qfprintf(ERR_STREAM,"Huge Character <%c> (%ld Bytes)\n", (char)c, (long)bytes);
  756.         ptr->charsize = HUGE_SIZE;
  757.         ptr->where.isloaded = _FALSE;
  758.       } else {
  759.         if ( (pr = (long4 *)malloc( bytes )) == NULL )
  760.             Fatal("Unable to allocate %ld bytes for char <%c>\n",
  761.                          (long)bytes, (char)c);
  762. /*
  763.  * else fprintf(ERR_STREAM,"allocating %ld bytes char <%c>(%d)\t at 0x%lx\n",
  764.  *                       (long)bytes, (char)c,(int)c,(long)pr);
  765.  */
  766. #ifdef DEBUG
  767.         if (Debug)
  768.           fprintf(ERR_STREAM,
  769.            "Allocating Char <%c>, FileOffset=%lX, Bytes=%ld (%d) <%d>\n",
  770.               (char) c, (long)ptr->where.address.fileOffset, (long)bytes,
  771.               (int)bytes, (unsigned int)bytes);
  772. #endif
  773.         allocated_storage += bytes;
  774.         read_multi(pr, 1, (int) bytes , pxlfp);
  775.         ptr->where.address.pixptr = pr;
  776.       }
  777.     }
  778. #else
  779.     FSEEK(gfin, ptr->where.address.fileOffset,SEEK_SET);
  780.     gettochar();
  781.     readbits();
  782.     if (num_bytes > HUGE_CHAR_PATTERN)
  783.       ptr->charsize = HUGE_SIZE;
  784. #endif
  785.     ptr->where.isloaded = _TRUE;
  786.     if (ptr->charsize != SMALL_SIZE
  787. #ifdef LJ
  788.         /* we might have problems at the edge of the paper with diff. sized characters
  789.          * the correct treatment would be to check whether the bounding box of
  790.          * tfontptr is within the paper relative to the current position
  791.          */
  792.     || fontptr->max_height > CHAR_HEIGTH_LARGE
  793.     || (rasterfont[fontptr->plusid])
  794. #endif
  795.        )
  796.         return;
  797.  
  798.     EmitChar(c, ptr);
  799. #ifdef USEPXL
  800.     /* we should really free the space used by the PXL data after this
  801.        point, but it is not large, and besides, we may want to be
  802.        more clever in the future, about sending bitmaps.  So keep
  803.        the data around */
  804. #endif
  805. }
  806.  
  807.  
  808. /*-->SetChar*/
  809. /**********************************************************************/
  810. /*****************************  SetChar  ******************************/
  811. /**********************************************************************/
  812. void
  813. SetChar(long4 c, short command, int PassNo, bool do_posn, bool in_string)
  814. {
  815.     register struct char_entry *ptr;  /* temporary char_entry pointer */
  816.     bool pos_after = _FALSE;
  817.  
  818.    ptr = &(fontptr->ch[c]);
  819.     if (!((ptr->where.isloaded) || (ptr->charsize == HUGE_SIZE)))
  820.         LoadAChar(c, ptr);
  821.     if (PassNo == 0)
  822.         return;
  823.  
  824.     if (do_posn) {
  825. #ifdef IBM3812
  826.         if (CharStringPos>0) {
  827.             fprintf(ERR_STREAM,"!!!! That should never happen!!!\n");
  828.             CharStringOut;
  829.         }
  830. #endif
  831.         SetPosn(h, v);
  832.     }
  833.  
  834. /*
  835. printf("(%d) hh=%ld (+%ld/+%ld), h=%ld, xh=%ld,xhh=%ld, [%ld|%ld] ->%d\n",
  836.     (int)do_posn,(long)hh,(long)ptr->cw,(long)ptr->cw*(long)hconv,(long)h,
  837.     (long)PIXROUND(h, hconv),
  838.     (long)PIXROUND(hh, hconv),
  839.     (long)labs((hh-h)),(long)hconv,(labs((hh-h))>hconv)
  840.     );
  841. */
  842.  
  843.     if (in_string && (labs((hh-h))>hconv)) {
  844. #ifdef IBM3812
  845.         CharStringOut;
  846. #endif
  847.         SetPosn(h, v);
  848.     }
  849.  
  850. /*
  851. fprintf(ERR_STREAM,"raster?=%d - last_ry=%d, last_rx=%d,mmax-height=%d\n",
  852.     (int)last_ry < fontptr->max_height, (int)last_ry,(int)last_rx,
  853.     (int)fontptr->max_height);
  854. */
  855.  
  856.     if (fontptr->font_file_id != NO_FILE) {      /* ignore missing fonts */
  857.          if (
  858. #ifdef LJ_RESIDENT_FONTS
  859.          !fontptr->resident_p &&
  860. #endif
  861.          (ptr->charsize != SMALL_SIZE
  862. #ifdef LJ
  863.           /* the LaserJet cannot print characters
  864.            * where the bounding box lies outside the
  865.            * paper edge. Missing: right paper edge
  866.            */
  867.           || last_ry < (int)fontptr->max_height
  868.           || fontptr->max_height > CHAR_HEIGTH_LARGE
  869.           || (rasterfont[fontptr->plusid])
  870. /***** KYOCERA *****/
  871. #ifdef SEVENBIT
  872.               || (c==32)
  873. #endif
  874. /***** KYOCERA *****/
  875. #endif
  876.           )) {
  877. #ifdef LJ
  878.       int     tmp;
  879.       char    sign;
  880.  
  881.       if (!do_posn) {
  882.         SetPosn(h, v);
  883.       }
  884. #ifdef USEPXL
  885.       tmp = (int) -ptr->yOffset;
  886. #else
  887.       tmp = (int) num_rows-y_offset;
  888. #endif
  889.       if (tmp != 0) {
  890.         if (tmp < 0) {
  891.           sign = '-'; tmp = -tmp;
  892.         } else
  893.           sign = '+';
  894.         EMIT(EMTO, "\033*p%c%dY", sign, tmp); EMFLUSH;
  895.       }
  896. #ifdef USEPXL
  897.       tmp = (int) -ptr->xOffset;
  898. #else
  899.       tmp = (int) -x_offset;
  900. #endif
  901.       if (tmp != 0) {
  902.         if (tmp < 0) {
  903.           sign = '-'; tmp = -tmp;
  904.         } else
  905.           sign = '+';
  906.         EMIT(EMTO, "\033*p%c%dX", sign, tmp); EMFLUSH;
  907.       }
  908. #endif
  909. #ifdef IBM3812
  910.       CharStringOut;
  911. #endif
  912. #ifdef DEBUG
  913.     if (Debug)
  914. #ifndef vms
  915.         fprintf(ERR_STREAM,"Raster character <%c> %hd\n", (char) c,(short)c);
  916. #else
  917.         fprintf(ERR_STREAM,"Raster character <%c> %d\n", (char) c,(short)c);
  918. #endif
  919. #endif
  920.             RasterChar(ptr);
  921.             pos_after = _TRUE;
  922.         } else {
  923.         unsigned char cc;
  924.         cc = VisChar((char)c);
  925. #ifdef IBM3812
  926. #ifdef USEPXL
  927.             if ( ptr->yyOffset || (!in_string) ) {
  928.                 CharStringOut;
  929.                 MoveVert(ptr->yyOffset);
  930.                 sprintf(PMPformat, "\01%c", cc);
  931.                 PMPout(2, PMPformat);
  932.                 MoveVert((int)-(ptr->yyOffset));
  933.             } else {
  934. #endif
  935.                 if (CharStringPos==CHARSTRINGMAX)
  936.                     CharStringOut;
  937.  
  938.                 CharString[CharStringPos] = cc;
  939.                 CharStringPos++;
  940. #ifdef USEPXL
  941.         }
  942. #endif
  943. #endif
  944. #ifdef LJ
  945. #define TRANSPARENTCHAR(ch) \
  946.         if ((ch == 0l) || (ch >= 7l && ch <= 15l) || (ch == 27l)) \
  947.         {EMIT(EMTO, "\033&p1X%c", (unsigned char)ch); EMFLUSH;} \
  948.         else {EMITC((unsigned char)ch);}
  949. #ifdef USEPXL
  950.             if (ptr->yyOffset) {
  951. #ifndef vms
  952.                 EMIT(EMTO, "\033*p+%hdY", ptr->yyOffset); EMFLUSH;
  953.                 TRANSPARENTCHAR(cc);
  954.                 EMIT(EMTO, "\033*p-%hdY", ptr->yyOffset); EMFLUSH;     /* GUGUGU 255 */
  955. #else
  956.                 EMIT(EMTO, "\033*p+%dY", ptr->yyOffset); EMFLUSH;
  957.                 TRANSPARENTCHAR(cc);
  958.                 EMIT(EMTO, "\033*p-%dY", ptr->yyOffset); EMFLUSH;    /* GUGUGU 255 */
  959. #endif
  960.             } else
  961. #endif
  962. /*                EMITC( (unsigned char)c);*/
  963.                { TRANSPARENTCHAR(cc);}
  964. #endif
  965.       }
  966.         hh += (long4) ptr->cw*hconv;
  967.     }
  968.     if (command <= SET4)
  969.         h += ptr->tfmw;
  970.     if (pos_after) {
  971.         SetPosn(h, v);
  972.       }
  973. }
  974.  
  975.  
  976. void
  977. DoBop(void)
  978. {
  979.     struct font_entry *p;
  980. #ifdef LJ
  981.     register short i;
  982.     if (fonts_used_on_this_page > MAX_FONTS_PER_PAGE) {
  983.        for (i = 0; i < HANDLE_MAX_FONTS; i++)
  984.           rasterfont[i] = _FALSE;
  985.     }
  986.     fonts_used_on_this_page = 0;
  987. #endif
  988.     for (p = hfontptr; p; p = p->next) {
  989.         p->used_on_this_page = _FALSE;
  990.     }
  991. }
  992.  
  993.  
  994. /*-->SetString*/
  995. /**********************************************************************/
  996. /*****************************  SetString  ****************************/
  997. /**********************************************************************/
  998. void
  999. SetString(short firstch, int PassNo)    /* read and set a consecutive string of chars */
  1000. {
  1001.     short   c;
  1002.     register unsigned short i;
  1003.  
  1004. #ifdef DEBUG
  1005.     if (Debug)
  1006.       fprintf(ERR_STREAM, "SetString ");
  1007. #endif
  1008.     for (i = 0, c = firstch; c >= SETC_000 && c <= SETC_127; i++) {
  1009. #ifdef DEBUG
  1010.         if (Debug)
  1011.           fprintf(ERR_STREAM, "%d(%c) ", c, c);
  1012. #endif
  1013.         SetChar((long4)c,  c, PassNo, (bool)(i==0),_TRUE);
  1014.         c = (short) NoSignExtend(dvifp, 1);
  1015.     }
  1016.     FSEEK(dvifp, -1l,SEEK_CUR);    /* backup one character */
  1017. #ifdef IBM3812
  1018.     CharStringOut;
  1019. #endif
  1020. #ifdef DEBUG
  1021.     if (Debug)
  1022.       fprintf(ERR_STREAM, "...SetString\n");
  1023. #endif
  1024. }
  1025.  
  1026.  
  1027. void
  1028. PutWord(w)
  1029. int     w;
  1030. {
  1031.     EMITC((char)(w >> 8) & 0xff);
  1032.     EMITC((char)w & 0xff);
  1033. }
  1034.  
  1035.  
  1036. /*-->SetPosn*/
  1037. /**********************************************************************/
  1038. /*****************************  SetPosn  ******************************/
  1039. /**********************************************************************/
  1040. void                  /* output a positioning command */
  1041. SetPosn(long4 x, long4 y)
  1042. {
  1043.     int     rx, ry;
  1044.     rx = (int)PIXROUND(x, hconv) + x_goffset;
  1045.     ry = (int)PIXROUND(y, vconv) + y_goffset;
  1046.  
  1047. /*
  1048. * fprintf(ERR_STREAM,"setposn to %ld/%ld, %d/%d\n",(long)x,(long)y,rx,ry);
  1049. */
  1050.  
  1051. #ifdef IBM3812
  1052.     PMPcont(3);
  1053.     PMPoutC('\340');
  1054.     EMITWORD(LARGER(rx,0));
  1055.  
  1056.     if (last_ry != ry) { /* necessary to set new y-position */
  1057.         PMPcont(3);
  1058.         PMPoutC('\341');
  1059.         EMITWORD(LARGER(ry,0));
  1060.     }
  1061. #endif
  1062. #ifdef LJ
  1063.     if (last_ry != ry)   /* necessary to set new y-position */
  1064.         {EMIT(EMTO, "\033*p%dx%dY", LARGER(rx,0), LARGER(ry,0)); EMFLUSH;}
  1065.     else
  1066.         {EMIT(EMTO, "\033*p%dX", LARGER(rx,0)); EMFLUSH;}
  1067. #endif
  1068.  
  1069.     last_ry = ry;    /* last y-position on output device */
  1070.     last_rx = rx;    /* last x-position on output device */
  1071. /*
  1072.  * must know where device "really" is horizontally, for rel. posning.
  1073.  * (maybe in the future), but we always use direct positioning for
  1074.  * vertical movement.
  1075.  */
  1076.     /* hh = rx * hconv; */
  1077.     hh = x;
  1078.     vv = y;
  1079. /*
  1080.  *     fprintf(ERR_STREAM,"DoPosn: x=%ld, y=%ld, rx=%d, ry=%d, hh=%ld, vv=%ld\n",
  1081.  *               (long)x,(long)y,rx,ry,(long)hh,(long)vv);
  1082.  */
  1083. }
  1084.